<?php
// 初始化星座变量
$zodiac = '';

// 处理表单提交
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // 获取用户输入的生日
    $birthdate = $_POST["birthdate"];
    $month = date('n', strtotime($birthdate));
    $day = date('j', strtotime($birthdate));

    // 根据生日计算星座
    if (($month == 3 && $day >= 21) || ($month == 4 && $day <= 19)) {
        $zodiac = "白羊座";
    } elseif (($month == 4 && $day >= 20) || ($month == 5 && $day <= 20)) {
        $zodiac = "金牛座";
    } elseif (($month == 5 && $day >= 21) || ($month == 6 && $day <= 20)) {
        $zodiac = "双子座";
    } elseif (($month == 6 && $day >= 21) || ($month == 7 && $day <= 22)) {
        $zodiac = "巨蟹座";
    } elseif (($month == 7 && $day >= 23) || ($month == 8 && $day <= 22)) {
        $zodiac = "狮子座";
    } elseif (($month == 8 && $day >= 23) || ($month == 9 && $day <= 22)) {
        $zodiac = "处女座";
    } elseif (($month == 9 && $day >= 23) || ($month == 10 && $day <= 22)) {
        $zodiac = "天秤座";
    } elseif (($month == 10 && $day >= 23) || ($month == 11 && $day <= 21)) {
        $zodiac = "天蝎座";
    } elseif (($month == 11 && $day >= 22) || ($month == 12 && $day <= 21)) {
        $zodiac = "射手座";
    } elseif (($month == 12 && $day >= 22) || ($month == 1 && $day <= 19)) {
        $zodiac = "摩羯座";
    } elseif (($month == 1 && $day >= 20) || ($month == 2 && $day <= 18)) {
        $zodiac = "水瓶座";
    } elseif (($month == 2 && $day >= 19) || ($month == 3 && $day <= 20)) {
        $zodiac = "双鱼座";
    }
}
?>

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>星座测算游戏</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <h1>星座测算游戏</h1>
    <form method="post">
        <label for="birthdate">请输入你的生日：</label>
        <input type="date" name="birthdate" id="birthdate" required>
        <input type="submit" value="测算星座">
    </form>
    <?php if ($zodiac): ?>
        <div id="result">
            <p>你的星座是：<?php echo $zodiac; ?></p>
        </div>
    <?php endif; ?>
</body>

</html>